shuffle dataframe python

32

shuffle rows dataframe -

df = df.sample(frac=1).reset_index(drop=True) #Use if you want to reset index order

df.sample(frac=1) # Use for no reset in index order

randomly shuffle pandas dataframe -

  shuffled_train_df = train_df.reindex(np.random.permutation(train_df.index))

Comments

Submit
0 Comments